from . import db
from ..utils.enums import MediaType


class Product(db.Model):
    __tablename__ = "sh_product"

    id = db.Column(db.Integer, primary_key=True)
    product_id = db.Column(db.String(64), unique=True, default="", doc="商品编号")
    title = db.Column(db.String(256), unique=True, default="", doc="商品名称")
    description = db.Column(db.String(256), unique=True, default="", doc="商品详情")
    deleted = db.Column(db.Boolean, doc="是否删除")
    product_images = db.relationship(
        "ProductImages", backref=db.backref("product", lazy="joined"), lazy="dynamic"
    )


class ProductImages(db.Model):
    __tablename__ = "sh_product_images"
    id = db.Column(db.Integer, primary_key=True)
    product_id = db.Column(db.Integer, db.ForeignKey("sh_product.id"))

    flie_type = db.Column(db.Enum(*MediaType.to_value_list()), server_default=MediaType.IMAGE.value)
    file = db.Column(db.String(256), doc="上传文件")
